//
//  CycleModel.m
//  网易新闻
//
//  Created by mac on 16/7/22.
//  Copyright © 2016年 xbk. All rights reserved.
//

#import "CycleModel.h"
#import "download.h"

@implementation CycleModel


+ (instancetype)CycleModelWithDic:(NSDictionary *)dic{

    CycleModel *model = [[CycleModel alloc]init];
    [model setValuesForKeysWithDictionary:dic];
    
    return model;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
}

+ (void) downloadDataWithUrl:(NSString *)urlStr successBlock:(void(^)(NSArray *listArr))successBlock failBlock:(void(^)(NSError *error))failBlock{

    [[download sharedownload]GET:urlStr parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *responseObject) {
        
        NSDictionary *dic = responseObject;
        
        //取key
        NSString *key = responseObject.keyEnumerator.nextObject;
        //数组
        NSArray *arr = dic[key];
        
        NSMutableArray *arrM = [NSMutableArray array];
        
        for (NSDictionary *dic in arr) {
            
            CycleModel *model = [CycleModel CycleModelWithDic:dic];
            
            [arrM addObject:model];
        }
        
        if (successBlock) {
            successBlock(arrM.copy);
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        if (failBlock) {
            failBlock(error);
        }
    }];
}

@end
